{extend name="layouts/base" /}
{block name="head" }
<link href="__STATIC__/main/css/stylesheets/uploadify/uploadify.min.css" rel="stylesheet"/>
<link href="__STATIC__/main/css/stylesheets/page/goods.css?v=1" rel="stylesheet"/>
{if condition="$row.isputaway == 1 || $row.isputaway == 10"}
<style>
    .js_file_upload,.item_new_close,.delete_sku_img,.specificationstable .file-item .info{display: none !important;}
</style>
{/if}
{/block}
{block name="main" }
<header>
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="fa fa-ellipsis-v"></i>
                <strong>{$row['goods_id']>0?"编辑商品":"添加商品"}</strong>
            </li>
        </ul>
        <a class="pull-right pointer p-r" data-toggle="back" title="返回"><i class="fa fa-reply"></i></a>
    </div>
</header>
<form class="form-horizontal form-validate form_vbox" method="post" action="{:url('info')}">
    <section class="vbox">
        <section class="scrollable wrapper w-f">
            <section class="panel panel-default">
                <div class="panel-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">商品名称：</label>
                        <div class="col-sm-7 must">
                            <input type="text" class="input-max" data-rule-maxlength="80" data-rule-required="true"
                                   data-msg-required="商品名称不能为空" name="goods_name" value="{$row.goods_name}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">商品简称：</label>
                        <div class="col-sm-5">
                            <input type="text" class="input-max" data-rule-maxlength="60" name="short_name"
                                   value="{$row.short_name}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">商品分类：</label>
                        <div class="col-sm-3 must">
                            <select name="cid" style="width:100%;" data-toggle="select2" data-placeholder="选择分类">
                                <option value="">选择分类</option>
                                {$classListOpt|raw}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">运费计算方式：</label>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input name="undertake" value="0" {$row.freight_template|tplckval='=0' ,'checked',true}
                                class="js_undertake" type="radio">卖家承担运费
                            </label>
                            <label class="radio-inline">
                                <input name="undertake" value="1" {$row['freight_template']>0 ||
                                $row['freight_template'] ==-1?'checked':''} class="js_undertake
                                js_freight_container_show" type="radio">
                                买家承担运费
                            </label>
                            <label class="js_freight_container"
                                   style="display:{$row['freight_template'] > 0 || $row['freight_template'] ==-1?'':'none'}; position:relative;">
                                <select name="freight_template" data-rule-required="true" aria-required="true"
                                        aria-invalid="true">
                                    <option value="-1" selected>-- 使用默认运费模板 --</option>
                                    {volist name="ShippingTpl" id="sfrow" }
                                    <option value="{$sfrow.sf_id}" {$row[
                                    'freight_template']==$sfrow['sf_id']?'selected':''}>{$sfrow.sf_name}{$sfrow['is_default']==1?'(默认)':''}</option>
                                    {/volist}
                                    {empty name="ShippingTpl"}
                                    <option value="0" selected>-- 没有运费模板 --</option>
                                    {/empty}
                                </select>
                            </label>

                        </div>
                    </div>
                    {if condition="$row['goods_id'] > 0" }
                    <div class="form-group">
                        <label class="col-sm-2 control-label">商品状态：</label>
                        <div class="col-sm-5 m-t-mc">
                            {$goods_status[$row['isputaway']]}
                        </div>
                    </div>
                    {/if}
                </div>

                <header>
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#basicInfo" data-toggle="tab">基本信息</a></li>
                        <li><a href="#otherInfo" data-toggle="tab">其它信息</a></li>
                        <!--<li><a href="#attribute" data-toggle="tab">商品属性</a></li>-->
                        {gt name="$row.goods_id" value="0"}
                        <li><a href="#log" data-toggle="tab">操作日志</a></li>
                        {/gt}
                    </ul>
                </header>

                <div class="tab-content">
                    <div class="tab-pane active" id="basicInfo">
                        {include file="goods/basicInfo" /}
                        {include file="goods/sku" /}
                    </div>
                    <div class="tab-pane" id="otherInfo">
                        {include file="goods/otherInfo" /}
                    </div>



                    <div class="tab-pane" id="attribute">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">商品模型：</label>
                            <div class="col-sm-3">
                                <select name="type_model" id="type_model" class="input-max " data-toggle="select2"
                                        onChange="getGoodsAttriBute()">
                                    <option value="0" selected>请选择模型</option>
                                    {$modelListOpt|raw}
                                </select>
                            </div>
                        </div>
                        <div id="goods_attribute_box">
                        </div>
                        <script type="text/javascript">
                            function getGoodsAttriBute() {
                                var type_model = $("#type_model").val();
                                $('#goods_attribute_box').html('');
                                if (type_model < 1) return false;
                                jq_ajax('{:_url("getAttriBute",array("goods_id"=>$row["goods_id"],"model_id"=>"【type_model】"))}', '', function (res) {
                                    if (res.code == 0) {
                                        _alert(res.msg);
                                        return false;
                                    }
                                    $('#goods_attribute_box').html(res.data.content);
                                });
                            }
                            $(function () {
                                getGoodsAttriBute();
                            });
                        </script>

                    </div>
                    {if condition="$row['goods_id'] > 0" }
                    <div class="tab-pane" id="log">
                        <table class="table table-bordered ">
                            <thead>
                            <tr>
                                <th width="180">记录时间</th>
                                <th width="150">操作者</th>
                                <th width="100">状态</th>
                                <th>备注</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="goodsLog" id="log"}
                            <tr>
                                <td>{$log.log_time|dateTpl}</td>
                                <td>{$log['opt_source']=='admin'?'平台-'.adminInfo($log['operator']):'供应商'}</td>
                                <td>{$log['status']}</td>
                                <td>{$log.log_info}</td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>
                    {/if}
                </div>

            </section>
        </section>
        <footer class="footer bg-white b-t p-t">
            <div class="form-group" style="width:90%;">
                <div class="col-sm-4 col-sm-offset-2">
                    {if condition="$row.isputaway != 1 && $row.isputaway != 10"}
                    <button type="submit" class="btn btn-primary js_save_submit" data-loading-text="保存中...">保存
                    </button>
                    {/if}
                    {gt name="$row.goods_id" value="0"}
                    {if condition="$row.isputaway != 1 && $row.isputaway != 10"}
                    <button type="button" data-msg="确定提交上架审核？"
                            data-remote="{:url('postCheck',array('goods_id'=>$row['goods_id']))}"
                            data-toggle="ajaxCurl" class="btn btn-palegreen js_save_submit">提交上架审核
                    </button>
                    {elseif condition="$row.isputaway == 1"}
                    <button type="button" data-msg="确定下架商品？"
                            data-remote="{:url('postUnder',array('goods_id'=>$row['goods_id']))}"
                            data-toggle="ajaxCurl" class="btn btn-palegreen js_save_submit"
                            data-loading-text="提交中...">下架商品
                    </button>
                    <button type="button" class="btn btn-primary" id="editStore">修改库存</button>
                    {/if}
                    {/gt}
                </div>
            </div>
            <input name="goods_id" id="goods_id" type="hidden" value="{$row.goods_id|intval}">

        </footer>
    </section>
</form>
{/block}


{block name="footer" }
<script type="text/javascript">
    seajs.use(["dist/plupload/init.js", "dist/goods/init.js"])
    $('#editStore').on('click', function () {
        var arr = $('.form-horizontal').toJson();
        jq_ajax('{:url("editStore")}', arr, function (res) {
            if (res.code == 0) {
                return _alert(res.msg);
            }
            window.location.reload();
        })
    })
</script>
{/block}